#pragma once

// import msado15.dll, the path may be different.
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF","adoEOF")

#include "mccommonapi.h"

#include <string>

namespace MCCommon
{

class MCAPI DBConnection
{
public:
    // Data base type.
    enum DBType
    {
        kDB_SQLServer,
        kDB_Oracle,
    };

public:
    /**
     * Constructor.
     * 
     */
    DBConnection
    (
        const std::string& serverName,
        const std::string& dbName,
        const std::string& userName,
        const std::string& passWord
    );

    /**
     * Destructor.
     * 
     */
    ~DBConnection();

    /**
     * Whether the connection is openned.
     * 
     */
    bool IsOpen( ) const;

    /**
     * Open the data base.
     * 
     */
    bool Open
    (
        const std::string& name,
        const std::string& password
    );

    /**
     * Close the connection.
     * 
     */
    void Close();

    /**
     * Execute sql.
     * 
     */
    bool ExecuteSQL
    (
        const std::string& sql
    );

    /**
     * Cancel asynchronous operation.
     * 
     */
    void Cancel();

    /**
     * Transaction support.
     * 
     */
    bool BeginTransaction();
    bool CommitTransaction();
    bool RollBack();

    /**
     * Set timeout for login and query.
     * 
     */
    void SetLoginTimeout( int secs );
    void SetQueryTimeout( int secs);

private:

    // The ado connection.
    _ConnectionPtr fpADOConnection;

    // The flag whether the connection is opened.
    bool fIsOpen;
};  

}// end of namespace MCCommon